package com.budwk.app.sqfw.controllers.admin;

import com.budwk.app.sqfw.dto.ThreeGuaranteeQueryDTO;
import com.budwk.app.sqfw.dto.ThreeGuaranteeControllerDTO;
import com.budwk.app.sqfw.dto.ThreeGuaranteeDTO;
import com.budwk.app.sqfw.services.ThreeGuaranteeService;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import com.budwk.starter.security.utils.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

/**
 * @author ZY.Wang
 * @since 2024/4/23
 */
@IocBean
@At("platform/assistance/threeGuarantee")
@ApiDefinition(tag = "门前三包表单")
@Slf4j
public class ThreeGuaranteeController {

    @Inject
    private ThreeGuaranteeService threeGuaranteeService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "录入门前三包数据")
    @SLog(tag = "录入表单数据", value = "${args[0]}")
    public Result<?> insertThreeGuarantee(@Param("..") ThreeGuaranteeControllerDTO threeGuaranteeDTO) {
        String userId = SecurityUtil.getUserId();
        threeGuaranteeService.insertThreeGuarantee(userId, threeGuaranteeDTO);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "根据storeId查询数据信息")
    @SLog(tag = "根据storeId查询数据信息", value = "${args[0]}")
    public Result<?> getStoreByStoreId(@Param("storeId") String storeId) {
        ThreeGuaranteeDTO resultVO = threeGuaranteeService.getStoreByStoreId(storeId);
        return Result.success(resultVO);
    }


    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "分页查询门前三包数据-供后台使用")
    public Result<?> pageListThreeGuarantee(@Param("..") ThreeGuaranteeQueryDTO queryDTO) {
        Pagination pagination = threeGuaranteeService.pageListThreeGuarantee(queryDTO);
        return Result.success(pagination);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "删除表单数据")
    public Result<?> deleteAssistanceFormSummary(@Param("id") String id) {
        threeGuaranteeService.deleteAssistanceFormSummary(id);
        return Result.success();
    }
}
